1 <?php
2     include(
"../includes/config.php");
3     include(
"../includes/validate_data.php");
4     session_start();
5     
if(isset($_SESSION['admin_login'])) {
6         
if($_SESSION['admin_login'] == true) {
7             $unitName = $unitDetails =
"";
8             $unitNameErr = $requireErr = $confirmMessage =
"";
9             $unitNameHolder = $unitDetailsHolder =
"";
10             
if($_SERVER['REQUEST_METHOD'] == "POST") {
11                 
if(!empty($_POST['txtUnitName'])) {
12                     $unitNameHolder = $_POST[
'txtUnitName'];
13                     $result = validate_name($_POST[
'txtUnitName']);
14                     
if($result == 1) {
15                         $unitName = $_POST[
'txtUnitName'];
16                     }
17                     
else{
18                         $unitNameErr = $result;
19                     }
20                 }
21                 
if(!empty($_POST['txtunitDetails'])) {
22                     $unitDetails = $_POST[
'txtunitDetails'];
23                     $unitDetailsHolder = $_POST[
'txtunitDetails'];
24                 }
25                 
if($unitName != null) {
26                     $query_addUnit =
"INSERT INTO unit(unit_name,unit_details) VALUES('$unitName','$unitDetails')";
27                     
if(mysqli_query($con,$query_addUnit)) {
28                         echo
"<script> alert(\"Unit Added Successfully\"); </script>";
29                         header(
'Refresh:0');
30                     }
31                     
else {
32                         $requireErr =
"Adding New Unit Failed";
33                     }
34                 }
35                 
else {
36                     $requireErr =
"* Valid Unit Name is required";
37                 }
38             }
39         }
40         
else {
41             header(
'Location:../index.php');
42         }
43     }
44     
else {
45         header(
'Location:../index.php');
46     }
47 ?>
48 <!DOCTYPE html>
49 <html>
50 <head>
51     <title> Add Unit </title>
52     <link rel=
"stylesheet" href="../includes/main_style.css" >
53 </head>
54 <body>
55     <?php
56         include(
"../includes/header.inc.php");
57         include(
"../includes/nav_admin.inc.php");
58         include(
"../includes/aside_admin.inc.php");
59     ?>
60     <section>
61         <h1>Add Unit</h1>
62         <form action=
"" method="POST" class="form">
63         <ul
class="form-list">
64         <li>
65             <div
class="label-block"> <label for="unitName">Unit Name</label> </div>
66             <div
class="input-box"> <input type="text" id="unitName" name="txtUnitName" placeholder="Unit Name" value="<?php echo $unitNameHolder; ?>" required /> </div> <span class="error_message"><?php echo $unitNameErr; ?></span>
67         </li>
68         <li>
69             <div
class="label-block"> <label for="unitDetails">Details</label> </div>
70             <div
class="input-box"><textarea id="unitDetails" name="txtunitDetails" placeholder="Details"><?php echo $unitDetailsHolder; ?></textarea> </div>
71         </li>
72         <li>
73             <input type=
"submit" value="Add Unit" class="submit_button" /> <span class="error_message"> <?php echo $requireErr; ?> </span><span class="confirm_message"> <?php echo $confirmMessage; ?> </span>
74         </li>
75         </ul>
76         </form>
77     </section>
78     <?php
79         include(
"../includes/footer.inc.php");
80     ?>
81 </body>
82 </html>


Gõ tìm kiếm nhanh...